package com.hcy.rabbitruntimeapi.center.handler;

import com.alibaba.fastjson.JSON;
import com.hcy.rabbitbasicmodel.common.MyWebSocketMessage;
import com.hcy.rabbitbasicutils.utils.RedisUtils;
import com.hcy.rabbitruntimeapi.center.MessageHandler;
import com.hcy.rabbitruntimeapi.center.MyMessageHandler;
import com.hcy.rabbitbasicmodel.enums.M_Code;
import com.hcy.schedulingclient.client.SchedulingLocationClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @Author huchenying
 * @Description 用户叫车时对订单的keepAlive
 * @Date 2021/12/15 19:28
 */
@MyMessageHandler(M_Code.CustomerKeepAliveOrder)
@Component
public class CustomerCallCarKeepAliveHandler extends MessageHandler {

    Logger logger = LoggerFactory.getLogger(CustomerCallCarKeepAliveHandler.class);

    @Autowired
    SchedulingLocationClient schedulingLocationClient;

    @Autowired
    RedisUtils redisUtils;

    @Override
    public void handler(MyWebSocketMessage myWebSocketMessage) {
//        logger.debug("CustomerCallCarKeepAliveHandler start code -> [{}] , desc -> [{}]", myWebSocketMessage.getCode(), myWebSocketMessage.getDesc());
        try {
            //解析数据体
            Object data = myWebSocketMessage.getData();
            //刷新 CallKeepALive:OrderNumber expire
            redisUtils.setCallOrderKeepAlive(data.toString(),data.toString(),10, TimeUnit.SECONDS);
        } catch (Exception e) {
            e.getStackTrace();
            logger.error("处理失败！reason -> {}",e.getMessage());
        }
    }
}
